﻿using UnityEngine;
using System.Collections;
using Dict.DataModel;
using ProtoBuf.Message;

namespace Room
{
    public class RCUIUnionFightNpc : RCUIPlayer
    {
        public TableUnionFightNpc dictData;

        float arriveDis;
        
        
        public RCUIUnionFightNpc(RoomCharactor owner)
            : base(owner)
        {
            this.owner = owner;
            type = UIType.UnionMine;
            ClickRange = (float)Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.UnionFightCanClickNpcRange;
            arriveDis = (float)Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.UnionFightArriveNpc;
        }

        public void Init(TableUnionFightNpc dictData)
        {
            this.dictData = dictData;
        }


        public void ClickEvent()
        {
            OnClick();
        }

        protected override void OnClick()
        {
            var self = owner.charactorManager.GetSelfCharactor();

            if(self!=null)
            {
                var ai = self.ai as RCAIUnionSelf;
                if (ai.Camp != dictData.Camp)
                    return;
                if(ai!=null && ai.IdleState() )
                {
                    ai.AutoGoto(owner.transform.position, () => 
                    {
                        if (ai.IdleState())
                        {
                            var runMapUI = UI.UIUnionFightRunMap.GetNetData().netGate.GetUI();
                            var obj = runMapUI.transform.Find(dictData.Url);
                            if (obj)
                            {
                                obj.GetComponent<UI.NPCUIPageTemplete>().SendCSMsg(dictData);
                            }
                        }
                    }, arriveDis);
                }
            }
        }
    }
}
